// 工具方法：从对象或字符串中提取conversation_id
export function extractConversationId(data) {
  if (!data) return undefined;
  if (typeof data === 'object' && data.conversation_id) {
    return data.conversation_id;
  }
  if (typeof data === 'string') {
    const matches = data.match(/data: (\{.*?\})(?=\n|$)/g) || data.match(/data: ({.*?})(?=\n|$)/g);
    if (matches) {
      for (const line of matches) {
        try {
          const obj = JSON.parse(line.replace(/^data: /, ''));
          if (obj.conversation_id) {
            return obj.conversation_id;
          }
        } catch (e) {}
      }
    }
  }
  return undefined;
} 